package com.qen.txt

import cn.hutool.core.io.FileUtil
import cn.hutool.core.io.file.FileAppender
import cn.hutool.core.io.file.FileReader
import cn.hutool.core.lang.Console
import com.qen.tianya.TanxuanExcelPath
import com.qen.yanshen.ZhihuOutFile
import com.qen.yanxuan.YanxuanOutFile
import java.io.File

const val YanxuanFilePath = "/Users/a1/Documents/Git/Kotlin/Eleven/out/txt"

fun main() {
    val file = File(YanxuanFilePath + "/盐选.txt")
    var appender = FileAppender(file, 16, true)


    val yanxuans = FileUtil.ls(TanxuanExcelPath + "/txt/")
    val list = ArrayList<File>()
    list.addAll(yanxuans.toList())
    for (i in 0..list.size - 1) {
        val it = list.get(i)
        if (i % 100 == 0) {
            appender.flush()
            appender.toString()
            appender = FileAppender(file, 16, true)
        }
        if (it.isFile && it.name.endsWith("txt")) {
            val reader = FileReader(it.path)
            appender.append("\n")
            appender.append(it.name.replace(".txt", ""))
            appender.append("\n")
            appender.append(reader.readString())
        }
        Console.log("$i:${it.name}:${it.length()}")
    }
    appender.flush()
    appender.toString()
}

fun main3() {
    val file = File(YanxuanFilePath + "/盐选.txt")
    var appender = FileAppender(file, 16, true)

    val files = FileUtil.ls(ZhihuOutFile)
    val yanxuans = FileUtil.ls(YanxuanOutFile + "/20241023/txt/")
    val list = ArrayList<File>()
    list.addAll(files.toList())
    list.addAll(yanxuans.toList())
    for (i in 0..list.size - 1) {
        val it = list.get(i)
        if (i % 100 == 0) {
            appender.flush()
            appender.toString()
            appender = FileAppender(file, 16, true)
        }
        if (it.isFile && it.name.endsWith("txt")) {
            val reader = FileReader(it.path)
            appender.append("\n")
            appender.append(it.name.replace(".txt", ""))
            appender.append("\n")
            appender.append(reader.readString())
        }
        Console.log("$i:${it.name}:${it.length()}")
    }
    appender.flush()
    appender.toString()
}

fun main1() {

    val appender = FileAppender(File(YanxuanFilePath + "/盐选.txt"), 16, true)
    appender.append("123")
    appender.append("abc")
    appender.append("xyz")

    appender.flush()
    appender.toString()
}

fun main2() {
    val files = FileUtil.ls(ZhihuOutFile)
    val yanxuans = FileUtil.ls(YanxuanFilePath)
    val list = ArrayList<File>()
    list.addAll(files.toList())
    list.addAll(yanxuans.toList())
    Console.log(list.size)
}